<template>
    <div>
        <div class="mt-3" style="color: #e37426;" @click="dialogFormVisible = true">
            修改个人信息
            <span style="font-family: 宋体,sans-serif;font-weight: 700"> > </span>
        </div>
        <el-dialog title="个人信息修改" :visible.sync="dialogFormVisible">
            <el-form :model="form" style="width: 90%">
                <el-form-item label="用户名" :label-width="formLabelWidth">
                    <el-input v-model="form.userName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="电话号码" :label-width="formLabelWidth">
                    <el-input v-model="form.userPhone" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="电子邮箱" :label-width="formLabelWidth">
                    <el-input v-model="form.userEmail" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="性别" :label-width="formLabelWidth">
                    <el-radio v-model="form.userSex"  label="1"  value="1">男</el-radio>
                    <el-radio v-model="form.userSex" label="2" value="0">女</el-radio>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary"
                           @click="dialogFormVisible==update()?dialogFormVisible = false:dialogFormVisible = false"
                           style="background-color: #e37426;border-color: #e37426">
                    确认修改
                </el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "changeMg",
        data(){
            return {
                
                form:{
                    id:localStorage.getItem('id'),
                    userName:'',
                    userPhone:'',
                    userEmail:'',
                    userSex:1
                },
                dialogFormVisible: false,
                formLabelWidth: '120px'
            }
        },
        mounted(){

           this.GetList();
           

        },
        methods:{
                 GetList(){
                this.axios
                .get("https://localhost:44347/api/app/p-user/"+this.form.id+"/s")
                .then(s=>
                {
                    
                    this.form.userName=s.data.userName;
                    this.form.userPhone=s.data.userPhone;
                    this.form.userEmail=s.data.userEmail;
                    this.form.userSex=s.data.userSex;

                        
                    
                })

            },
            update(){
                this.axios
                .put("https://localhost:44347/api/app/p-user/user",this.form)
                .then(s=>{
                   if(s.data>0)
                   {
                       alert("修改成功")
                       localStorage.setItem("username",this.form.userName)
                        this.$router.go(0);      //页面刷新
                   }
                   else
                   {
                       alert("修改失败")
                       this.$router.go(0);      //页面刷新
                       
                   }
                })
            }

        }

    }
</script>

<style scoped>

</style>